// 导包
let sql = require('mysql');
//创建数据池
let pool = sql.createPool({
    host: 'localhost',
    user: 'root',
    password: 'root',
    database: 'wanbiaonet',
    connectionLimit: 20,
    timeout: 1000 * 20
})

// 数据查询
const exec = (sql, params) => {
    return new Promise((resolve, reject) => {
        pool.getConnection((err, conn) => {
            if (err) {
                reject('连接错误:' + err)
            }
            conn.query(sql, params, function (err, res) {
                if (err) {
                    reject('执行sql错误:' + err.sqlMessage)
                }
                resolve(res)
                conn.release();
            })
        })
    })
}

module.exports = {
    exec
}

